package com.c3w.synchro.member.bean;

import com.c3w.synchro.common.bean.Bean;

import javax.persistence.*;


/**
 * User: magirard
 * Date: 12-10-02
 */
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Member extends Bean {
    public enum Gender {
        M, F
    }

    @Column(nullable = false)
    private String name;

    private int age;

    @Column(nullable = false)
    private Gender gender;

    @OneToOne(cascade = CascadeType.ALL, optional = true, fetch = FetchType.LAZY)
    private ContactInfo contactInfo;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public ContactInfo getContactInfo() {
        return contactInfo;
    }

    public void setContactInfo(ContactInfo contactInfo) {
        this.contactInfo = contactInfo;
    }

    public Gender getGender() {
        return gender;
    }

    public void setGender(Gender gender) {
        this.gender = gender;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Member)) return false;
        if (!super.equals(o)) return false;

        Member member = (Member) o;

        if (age != member.age) return false;
        if (gender != member.gender) return false;
        if (name != null ? !name.equals(member.name) : member.name != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + age;
        result = 31 * result + (gender != null ? gender.hashCode() : 0);
        return result;
    }
}
